package com.example.heyue.educationmp4.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.vipheyue.educationmp4.R;
import com.vipheyue.educationmp4.tabSample.CycleActivity;
import com.vipheyue.fastlib.adapter.BaseRecyclerAdapter;
import com.vipheyue.fastlib.adapter.BaseRecyclerViewHolder;
import com.yqritc.recyclerviewflexibledivider.HorizontalDividerItemDecoration;

import java.util.ArrayList;
import java.util.Arrays;

import butterknife.Bind;
import butterknife.ButterKnife;

public class SampleTabMainActivity extends AppCompatActivity {

    @Bind(R.id.recycler)
    RecyclerView recyclerView;
    ArrayList<String> mdata = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);
        initData();
//        btn_test.setOnClickListener(v->{
//            Toast.makeText(this, "xxx", Toast.LENGTH_SHORT).show(); });
//        btn_test.setOnClickListener(v -> Toast.makeText(SampleTabMainActivity.this, "xxxRR", Toast.LENGTH_SHORT).show());
    }

    private void initData() {
        String[] array = {"1级上", "1级下", "2级上", "2级下", "3级上", "3级下", "4级上", "4级下", "5级上", "5级下"};
        mdata = new ArrayList(Arrays.asList(array));
        GridLayoutManager layoutManager = new GridLayoutManager(this, 2);
//        LinearLayoutManager layoutManager = new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false);
        recyclerView.setLayoutManager(layoutManager);//设置显示方式
        recyclerView.addItemDecoration(new HorizontalDividerItemDecoration.Builder(this)//第三
//                .drawable(R.drawable.sample)///图片
                .drawable(R.drawable.divider)
                .size(0)
                .build());

        BaseRecyclerAdapter adapter = new BaseRecyclerAdapter<String>(this, mdata, R.layout.activity_item) {
            @Override
            public void init(BaseRecyclerViewHolder holder, String bean, int position) {
                holder.setText(R.id.tv_item, mdata.get(position));
            }
        };
        adapter.setOnItemClickLinster(new BaseRecyclerAdapter.OnItemClickLinster() {
            @Override
            public void onItemClick(View view, int position) {
                startActivity(new Intent(SampleTabMainActivity.this, CycleActivity.class));
            }
        });
        recyclerView.setAdapter(adapter);//设置适配器

    }

}
